package com.app.mymobileweb;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.*;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.repackaged.org.json.JSONArray;



@SuppressWarnings("serial")
public class MobileWebServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		//resp.getWriter().println("Hello, world");
		resp.getWriter().println("Your Valuable Feedback is Successfully Submitted!");
		//String username = req.getParameter("fb");
		//System.out.println("username is "+username);

		PrintWriter out = resp.getWriter();
		 
		JSONArray arrayObj=new JSONArray();
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("feedback");
		List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
		int sizeofdatabase = results.size()+1;
		String name= req.getParameter("name");
		String email= req.getParameter("email");
		String comments= req.getParameter("comments");
		Entity feedbacks = new Entity("feedback",sizeofdatabase);
		feedbacks.setProperty("name",name);
		feedbacks.setProperty("email",email);
		feedbacks.setProperty("comments",comments);
		datastore.put(feedbacks);
		q.getSortPredicates();
	}
}
